﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using nERP.Model.Fin;
using nERP.Model;
using nERP.Model.So;

namespace nERP.ViewModel.Fin.ReceivableDetailVMs
{
    public partial class ReceivableDetailListVM : BasePagedListVM<ReceivableDetail_View, ReceivableDetailSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ReceivableDetail_View>> InitGridHeader()
        {
            return new List<GridColumn<ReceivableDetail_View>>{
                
                this.MakeGridHeader(x => x.ReceivableDetail_Seq).SetTitle(@Localizer["Page.序号"].Value),
                this.MakeGridHeader(x => x.ReceivableDetail_Receivable).SetTitle(@Localizer["Page.收款单"].Value),
                this.MakeGridHeader(x => x.ReceivableDetail_ReceivableDetailCode).SetTitle(@Localizer["Page.收款明细单号"].Value),
                this.MakeGridHeader(x => x.ReceivableDetail_Sale).SetTitle(@Localizer["Page.销售订单"].Value),
                this.MakeGridHeader(x => x.ReceivableDetail_Amount1).SetTitle(@Localizer["Page.单据金额"].Value),
                this.MakeGridHeader(x => x.ReceivableDetail_Amount2).SetTitle(@Localizer["Page.已结金额"].Value),
                this.MakeGridHeader(x => x.ReceivableDetail_Amount3).SetTitle(@Localizer["Page.未结金额"].Value),
                this.MakeGridHeader(x => x.ReceivableDetail_Amount4).SetTitle(@Localizer["Page.本次结算金额"].Value),
                this.MakeGridHeader(x => x.ReceivableDetail_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.ReceivableDetail_Status).SetTitle(@Localizer["Page.状态"].Value),
                this.MakeGridHeader(x => x.ReceivableDetail_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ReceivableDetail_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ReceivableDetail_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ReceivableDetail_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ReceivableDetail_View> GetSearchQuery()
        {
            var query = DC.Set<ReceivableDetail>()
                
                .CheckEqual(Searcher.Seq, x=>x.Seq)
                .CheckEqual(Searcher.ReceivableId, x=>x.ReceivableId)
                .CheckContain(Searcher.ReceivableDetailCode, x=>x.ReceivableDetailCode)
                .CheckEqual(Searcher.SaleId, x=>x.SaleId)
                .CheckEqual(Searcher.Amount1, x=>x.Amount1)
                .CheckEqual(Searcher.Amount2, x=>x.Amount2)
                .CheckEqual(Searcher.Amount3, x=>x.Amount3)
                .CheckEqual(Searcher.Amount4, x=>x.Amount4)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckEqual(Searcher.Status, x => x.Status)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ReceivableDetail_View
                {
				    ID = x.ID,
                    
                    ReceivableDetail_Seq = x.Seq,
                    ReceivableDetail_Receivable = DC.Set<Receivable>().Where(z0 => z0.ReceivableCode == x.ReceivableId).Select(y => y.ReceivableCode).FirstOrDefault(),
                    ReceivableDetail_ReceivableDetailCode = x.ReceivableDetailCode,
                    ReceivableDetail_Sale = DC.Set<Sale>().Where(z0 => z0.SaleCode == x.SaleId).Select(y => y.SaleCode).FirstOrDefault(),
                    ReceivableDetail_Amount1 = x.Amount1,
                    ReceivableDetail_Amount2 = x.Amount2,
                    ReceivableDetail_Amount3 = x.Amount3,
                    ReceivableDetail_Amount4 = x.Amount4,
                    ReceivableDetail_Remark = x.Remark,
                    ReceivableDetail_Status = x.Status,
                    ReceivableDetail_CreateTime = x.CreateTime,
                    ReceivableDetail_UpdateTime = x.UpdateTime,
                    ReceivableDetail_CreateBy = x.CreateBy,
                    ReceivableDetail_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ReceivableDetail_View: ReceivableDetail
    {
        
        public int? ReceivableDetail_Seq { get; set; }
        public string ReceivableDetail_Receivable { get; set; }
        public string ReceivableDetail_ReceivableDetailCode { get; set; }
        public string ReceivableDetail_Sale { get; set; }
        public decimal? ReceivableDetail_Amount1 { get; set; }
        public decimal? ReceivableDetail_Amount2 { get; set; }
        public decimal? ReceivableDetail_Amount3 { get; set; }
        public decimal? ReceivableDetail_Amount4 { get; set; }
        public string ReceivableDetail_Remark { get; set; }
        public dStatusTypeEnum? ReceivableDetail_Status { get; set; }
        public DateTime? ReceivableDetail_CreateTime { get; set; }
        public DateTime? ReceivableDetail_UpdateTime { get; set; }
        public string ReceivableDetail_CreateBy { get; set; }
        public string ReceivableDetail_UpdateBy { get; set; }

    }

}